/**
 * 
 */
package com.eis.persist.dao.base;

import java.util.Date;

import org.springframework.jdbc.core.JdbcTemplate;

import com.eis.persist.model.base.BasePersist;

/**
 * @author panwei01
 *
 */
public abstract class BaseDAO {
	protected JdbcTemplate dataSource; 
	protected String currentUserName;
	
	public BaseDAO(JdbcTemplate dataSource, String currentUserName) {
		super();
		this.dataSource = dataSource;
		this.currentUserName = currentUserName;
	}
	
	public BaseDAO(JdbcTemplate dataSource) {
		this(dataSource, "Unknown User");
	}
	
	protected BasePersist preInsert(BasePersist basePersist) {
		basePersist.setCreateDate(new Date());
		basePersist.setCreatedBy(currentUserName);
		
		return basePersist;
	}
	
	protected BasePersist preUpdate(BasePersist basePersist) {
		basePersist.setUpdateDate(new Date());
		basePersist.setUpdatedBy(currentUserName);
		
		return basePersist;
	}
}
